package com.shangxian.giveithome.controller;


import com.shangxian.giveithome.entity.*;
import com.shangxian.giveithome.result.Result;
import com.shangxian.giveithome.service.MechanismFeiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "机构Fei")
@Component
@RestController
@RequestMapping("/mechanismFei")
public class MechanismServer {

  @Autowired
  private MechanismFeiService mechanismFeiService;

//  public MechanismDetails queryByMe(Long id) {
//    return mechanismFeiService.queryByMe(id);
//  }
  @ApiOperation(value = "根据用户id查询所属机构管理信息")
  @PostMapping(value = "/queryByMe", name = "根据用户id查询所属机构管理信息")
  public MechanismDetails queryByMe(Long id) {
    return mechanismFeiService.queryByMe(id);
  }

//  public Mechanism queryByMechanismId(Long meId) {
//    return mechanismFeiService.queryByMechanismId(meId);
//  }
  @ApiOperation(value = "简单查询机构名称与图片")
  @GetMapping("/queryMechanismId/{meId}")
  public Mechanism queryByMechanismId(Long meId) {
    return mechanismFeiService.queryByMechanismId(meId);
  }

//  public Mechanism queryByMechanismAsylum(Long me_id) {
//    return mechanismFeiService.queryByMechanismAsylum(me_id);
//  }
  @ApiOperation(value = "")
  @GetMapping("/queryMechanismAsylum/{me_id}")
  public Mechanism queryByMechanismAsylum(Long me_id) {
    return  mechanismFeiService.queryByMechanismAsylum(me_id);
  }

//  public Long queryById(Long id) {
//    return mechanismFeiService.queryById(id);
//  }
  @ApiOperation(value = "")
  @GetMapping("/queryId")
  public Long queryById(Long id) {
    return mechanismFeiService.queryById(id);
  }


//  public PageableDetails queryUserActivity(Long id, Long offSet, Pageable pageable) {
//    return mechanismFeiService.queryUserActivity(id, offSet, pageable);
//  }
  @ApiOperation(value = "查询用户活动信息")
  @GetMapping("/queryUserActivity/{id}/{offSet}")
  public PageableDetails queryUserActivity(Long id,Long offSet, Pageable pageable) {
    return mechanismFeiService.queryUserActivity(id, offSet, pageable);
  }

//  public PageableDetails queryUserActivityHistory(Long id, Long offSet, Pageable pageable) {
//    return mechanismFeiService.queryUserActivityHistory(id, offSet, pageable);
//  }
  @ApiOperation(value = "查询用户活动信息-历史")
  @GetMapping("/queryUserActivityHistory/{id}/{offSet}")
  public PageableDetails queryUserActivityHistory(@PathVariable Long id, @PathVariable Long offSet, Pageable pageable) {
    return mechanismFeiService.queryUserActivityHistory(id, offSet, pageable);
  }

//  public List<Mechanism> queryByUserAdoption(List<Long> mes) {
//    return mechanismFeiService.queryByUserAdoption(mes);
//  }
  @ApiOperation(value = "查询用户-领养相关信息")
  @GetMapping("/queryByUserAdoption")
  public List<Mechanism> queryByUserAdoption(@RequestParam(value = "mes") List<Long> mes) {
    return mechanismFeiService.queryByUserAdoption(mes);
  }

//  public List<VolunteerUser> queryByUserVolunteer(Long us_id) {
//    return mechanismFeiService.queryVolunteer(us_id);
//  }
  @ApiOperation(value = "")
  @GetMapping("/queryUserVolunteer/{us_id}")
  public List<VolunteerUser> queryByUserVolunteer(@PathVariable Long us_id) {
    return mechanismFeiService.queryVolunteer(us_id);
  }

//  public void updateMechanismData(MechanismDataUp mechanismDataUp) {
//    mechanismFeiService.upMechanismData(mechanismDataUp);
//  }
  @ApiOperation(value = "修改机构数据")
  @PostMapping("/updateMechanismData")
  public void updateMechanismData(@RequestBody MechanismDataUp mechanismDataUp) {
    mechanismFeiService.upMechanismData(mechanismDataUp);
  }

  /**
   * 查看申请成为机构的信息
   *
   * @return
   */
  @ApiOperation(value = "查看申请成为机构的信息")
  @GetMapping("/queryMechanismApply")
  public Result queryMechanismApply(@PageableDefault(page = 0, size = 10) Pageable pageable) {
    return Result.success(mechanismFeiService.queryMechanismApply(pageable));
  }

  /**
   * 通过
   *
   * @param id
   * @return
   */
  @ApiOperation(value = "通过")
  @PostMapping("/successMechanism")
  public Result successMechanism(Long id) {
    mechanismFeiService.success(id);
    return Result.success();
  }

  /**
   * 不通过
   */
  @ApiOperation(value = "不通过")
  @PostMapping("/errorMechanism")
  public Result errorMechanism(Long id) {
    mechanismFeiService.error(id);
    return Result.success();
  }

}
